package com.epoint.BookManager.service;

import java.util.List;

import com.epoint.BookManager.dao.BookInfoDao;
import com.epoint.BookManager.dao.borrowInfoDao;
import com.epoint.BookManager.domain.BookInfo;
import com.epoint.BookManager.domain.BorrowInfo;

public class BorrowInfoService {

	borrowInfoDao borrow = new borrowInfoDao();
	BookInfoDao bookInfoDao = new BookInfoDao();

	/**
	 * 展示借阅信息列表
	 * 
	 * @param pageIndex
	 * @param pageSize
	 * @param sortField
	 * @param sortOrder
	 * @return
	 */
	public List<BorrowInfo> getBookList(int pageIndex, int pageSize, String sortField, String sortOrder) {
		return borrow.getBookList(pageIndex, pageSize, sortField, sortOrder);
	}

	/**
	 * 查询所有可以借阅的书籍
	 * 
	 * @return
	 */
	public List<BookInfo> getCanChanceList() {
		return bookInfoDao.CanListBychance();
	}

	/**
	 * 获取借阅ID后四位数字
	 * 
	 * @return
	 */
	public String getBorrowId() {
		String borrorID = borrow.getBorrorID();
		String str = String.format("%04d", Integer.valueOf(borrorID) + 1);
		return str;
	}

	/**
	 * 插入借阅信息
	 * 
	 * @param borrowInfo
	 * @return
	 */
	public boolean borrowAdd(BorrowInfo borrowInfo) {
		return borrow.borrowBook(borrowInfo) == 2;

	}

	/**
	 * 删除借阅信息
	 * 
	 * @param borrowid
	 * @return
	 */
	public boolean deleteBorrowInfo(String borrowid) {
		return borrow.deleteBorrowinfo(borrowid) == 1;
	}
	
	/**
	 * 还书
	 * 
	 * @param borrowid
	 * @param bookid
	 * @return
	 */
	public boolean returnBook(String borrowid, String bookid) {
		return borrow.returnBook(borrowid, bookid) == 2;
	}

}
